package com.zh.note.huawei.onehundred.求字符串中所有整数的最小和;

/**
 * @Author: zhanghuan
 * @date: 2023/9/3 14:34
 * @description: create it
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        try {
            Scanner s = new Scanner(System.in);
            // String values = s.nextLine();
            String values = "bb12-34aa";
            sovle(values);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("input error");
        }
    }

    public static void sovle(String values) {
        boolean flag = false;//负数的标志
        String tempNumber = "-";//用来记录负数的字符串
        List<Integer> myList = new ArrayList<>();
        for (int j = 0; j < values.length(); ++j) {
            char ch = values.charAt(j);
            if (ch == '-') {//找到负数
                flag = true;
                continue;
            }
            if (ch <= '9' && ch >= '0') {
                if (flag) { //是负数,需要拼接字符串
                    tempNumber += ch;
                } else {
                    // 不是负数直接加入list
                    myList.add(Integer.parseInt(String.valueOf(ch)));
                }
            } else { //是字母
                if (tempNumber != "-") {
                    myList.add(Integer.parseInt(tempNumber));
                    tempNumber = "-";
                }
                flag = false;
            }
        }
        int sum = 0;
        for (int j = 0; j < myList.size(); ++j) {
            sum += myList.get(j);
        }
        System.out.println(sum);
    }


}
